package com.ssm.song.book.service.impl;

import com.ssm.song.book.domain.Category;
import com.ssm.song.book.domain.Reader;
import com.ssm.song.book.domain.vo.BookVo;
import com.ssm.song.book.mapper.BookMapper;
import com.ssm.song.book.mapper.CategoryMapper;
import com.ssm.song.book.mapper.ReaderMapper;
import com.ssm.song.book.service.IBookService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 宋伟宁
 * @Date 2023/10/16
 * @Version 1.0
 **/
@Service
public class BookService implements IBookService {
    @Resource
    private BookMapper bookMapper;
    @Resource
    private CategoryMapper categoryMapper;

    @Resource
    private ReaderMapper readerMapper;

    @Override
    public List<BookVo> findAll() {
        return this.bookMapper.findAll();
    }

    @Override
    public Boolean addCategory(Category category) {
        return this.categoryMapper.insertSelective(category)==1;
    }

    @Override
    public List<Category> getCategorys() {
        return this.categoryMapper.findAll();
    }

    @Override
    public boolean deleteCategory(long cid) {
        return this.categoryMapper.deleteByPrimaryKey(cid) ==1;
    }

    @Override
    public boolean updateCategory(Category category) {
        return this.categoryMapper.updateByPrimaryKey(category)==1;
    }

    @Override
    public boolean addReader(Reader reader) {
        return this.readerMapper.insertSelective(reader)==1;
    }
}
